﻿/**
  ******************************************************************************
  * @file    Libraries/Device/JS32T031/JS32T031_LL_Driver/inc/js32t031_ll_gpio.h
  * @author  JUSHENG Application Team
  * @version V1.0.0
  * @date    02-19-2022
  * @brief   This file contains all the GPIO LL firmware functions.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2022 JUSHENG</center></h2>
  *
  *
  *
  ******************************************************************************
  */ 
  
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __JS32T031_LL_GPIO_H
#define __JS32T031_LL_GPIO_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "js32t031.h"

/** @addtogroup JS32T031_StdPeriph_Driver JS32T031 Driver
  * @{
  */
     
/** @addtogroup gpio_interface_gr GPIO Driver
  * @ingroup  JS32T031_StdPeriph_Driver
  * @{
  */ 

/** @addtogroup GPIO_LL_Driver GPIO LL Driver
  * @ingroup  gpio_interface_gr
  * @brief Mainly the driver part of the GPIO module, which includes \b GPIO \b Register 
  * \b Constants, \b GPIO \b Exported \b Constants, \b GPIO \b Exported \b Struct, \b GPIO
  * \b Data \b transfers \b functions, \b GPIO \b Initialization \b and \b GPIO \b Configuration 
  * \b And \b Interrupt \b Handle \b function.
  * @{
  */

/* Exported types ------------------------------------------------------------*/

/* Exported constants --------------------------------------------------------*/

/** @defgroup GPIO_LL_Register_Constants GPIO LL Register Constants
  * @ingroup  GPIO_LL_Driver
  * @brief    GPIO LL register constant table definition
  *
  *
@verbatim   
  ===============================================================================
                                Register Constants
  ===============================================================================  
  
    Register Constants mainly encapsulates each bit in each group in the GPIO 
    register. In the process of configuration, the macro definition can be directly 
    called to configure the GPIO register, mainly for convenience. Understand the 
    configuration of the GPIO.
    
@endverbatim
  *
  * @{
  */


/**
  * @}
  */

/** @defgroup GPIO_LL_Exported_Constants GPIO LL Exported Constants
  * @ingroup  GPIO_LL_Driver
  * @brief    GPIO LL external constant definition
  *
@verbatim   
  ===============================================================================
                                Exported Constants
  ===============================================================================  
  
    Exported Constants mainly restricts the partial configuration of the abstraction 
    layer by using the form of enumeration to facilitate the use and understanding of 
    the module configuration. For the specific enumeration meaning, please refer to 
    the annotation of each module.

    Alternation funtion:
    ========================================================================
    Port       AF0                   AF1          |             TK_ID
    ========================================================================
    PA0     UST0_CS               UART1_RX        |             TK10
    PA1     UST0_SCK              UART1_TX        |             TK11
    PA2     UST0_IO0              SPI0_NSS        |             TK12
    PA3     UST0_IO1              SPI0_SCK        |             TK13
    PA4     TMR4_CH               SPI0_IO0        |             TK14
    PA5     UST0_IO1              SPIO_IO1        |             TK15
    PA6     PORT_WKUP_IN0         TMR0_CH         |             TK16
    PA7     UST0_IO0              TMR1_CH         |             TK17
    PA8     UST0_SCK              UART1_RX        |             TK18
    PA9     UST0_CS               TMR1_CH         |             TK19
    PA10    UART0_RX              SPI0_NSS        |             TK20
    PA11    UART0_TX              SPI0_SCK        |             TK21
    PA12    PORT_WKUP_IN1         SPI0_IO0        |             TK22
    PA13    PORT_WKUP_IN2         SPI0_IO1        |             TK23
    PA14    UART0_RX              SPI0_SCK        |             TK24
    PA15    UART0_TX              SPI0_IO0        |             TK25
    PB0     TMR1_CH               UST0_CS         |             TK0
    PB1     UART1_RX              UST0_SCK        |             TK1
    PB2     UART1_TX              UST0_IO0        |             TK2
    PB3     UART0_RX              UST0_IO1        |             TK3
    PB4     UART0_TX              TMR1_CH         |             TK4
    PB5     PORT_WKUP3            SYS_NMI_IN      |             TK5
    PB6     TMR4_CH               UART0_RX        |             TK6
    PB7     TMR4_SYNCI_IO         TMR4_CH         |             TK7
    PB8     TMR0_CH               TMR1_CH         |             TK8
    PB9     TMR0_CH               TMR0_SYNCI_IO   |             TK9
    PB10    PORT_WKUP_IN0         UART0_RX        |             /
    PB11    PORT_WKUP_IN1         UART0_TX        |             /
    PB12    PORT_WKUP_IN2         TMR0_CH         |             /
    PB13    PORT_WKUP_IN3         TMR1_CH         |             /
    --------------------------------------------------------------------
    
    Note:
    =======================================
    SPI mode       remap         IIC mode
    =======================================
    SPI0_NSS        =>
    SPI0_SCK        =>            IIC_CLK
    SPI0_IO0        =>            IIC_DAT
    SPI0_IO1        =>
    =======================================

    =====================================================================
    UST           UART mode          SPI mode         PWM for timer mode
    =====================================================================
    UST0_CS        -                 SPI_NSS           PWM0
    UST0_SCK       -                 SPI_CLK           PWM1
    UST0_IO0       TX                SPI_IO0           PWM2
    UST0_IO1       RX                SPI_IO1           PWM3
    =====================================================================

@endverbatim
  *
  * @{
  */

#define GPIO_BITBAND_REG(Reg,Bit)    (*((uint32_t volatile*)(0x42000000u + (((uint32_t)&(Reg) - (uint32_t)0x40000000u)<<5) + (((uint32_t)(Bit))<<2))))
//GPIO_OUT
#define PA0_OUT       GPIO_BITBAND_REG(GPIOA->ODAT, 0) 
#define PA1_OUT       GPIO_BITBAND_REG(GPIOA->ODAT, 1)
#define PA2_OUT       GPIO_BITBAND_REG(GPIOA->ODAT, 2)
#define PA3_OUT       GPIO_BITBAND_REG(GPIOA->ODAT, 3)
#define PA4_OUT       GPIO_BITBAND_REG(GPIOA->ODAT, 4)
#define PA5_OUT       GPIO_BITBAND_REG(GPIOA->ODAT, 5)
#define PA6_OUT       GPIO_BITBAND_REG(GPIOA->ODAT, 6)
#define PA7_OUT       GPIO_BITBAND_REG(GPIOA->ODAT, 7)
#define PA8_OUT       GPIO_BITBAND_REG(GPIOA->ODAT, 8)
#define PA9_OUT       GPIO_BITBAND_REG(GPIOA->ODAT, 9)
#define PA10_OUT      GPIO_BITBAND_REG(GPIOA->ODAT, 10)
#define PA11_OUT      GPIO_BITBAND_REG(GPIOA->ODAT, 11)
#define PA12_OUT      GPIO_BITBAND_REG(GPIOA->ODAT, 12)
#define PA13_OUT      GPIO_BITBAND_REG(GPIOA->ODAT, 13)
#define PA14_OUT      GPIO_BITBAND_REG(GPIOA->ODAT, 14)
#define PA15_OUT      GPIO_BITBAND_REG(GPIOA->ODAT, 15)

#define PB0_OUT       GPIO_BITBAND_REG(GPIOB->ODAT, 0)
#define PB1_OUT       GPIO_BITBAND_REG(GPIOB->ODAT, 1)
#define PB2_OUT       GPIO_BITBAND_REG(GPIOB->ODAT, 2)
#define PB3_OUT       GPIO_BITBAND_REG(GPIOB->ODAT, 3)
#define PB4_OUT       GPIO_BITBAND_REG(GPIOB->ODAT, 4)
#define PB5_OUT       GPIO_BITBAND_REG(GPIOB->ODAT, 5)
#define PB6_OUT       GPIO_BITBAND_REG(GPIOB->ODAT, 6)
#define PB7_OUT       GPIO_BITBAND_REG(GPIOB->ODAT, 7)
#define PB8_OUT       GPIO_BITBAND_REG(GPIOB->ODAT, 8)
#define PB9_OUT       GPIO_BITBAND_REG(GPIOB->ODAT, 9)
#define PB10_OUT      GPIO_BITBAND_REG(GPIOB->ODAT, 10)
#define PB11_OUT      GPIO_BITBAND_REG(GPIOB->ODAT, 11)
#define PB12_OUT      GPIO_BITBAND_REG(GPIOB->ODAT, 12)
#define PB13_OUT      GPIO_BITBAND_REG(GPIOB->ODAT, 13)


//GPIO_IN
#define PA0_IN       ((GPIOA->IDAT >> 0)&0x01)
#define PA1_IN       ((GPIOA->IDAT >> 1)&0x01)
#define PA2_IN       ((GPIOA->IDAT >> 2)&0x01)
#define PA3_IN       ((GPIOA->IDAT >> 3)&0x01)
#define PA4_IN       ((GPIOA->IDAT >> 4)&0x01)
#define PA5_IN       ((GPIOA->IDAT >> 5)&0x01)
#define PA6_IN       ((GPIOA->IDAT >> 6)&0x01)
#define PA7_IN       ((GPIOA->IDAT >> 7)&0x01)
#define PA8_IN       ((GPIOA->IDAT >> 8)&0x01)
#define PA9_IN       ((GPIOA->IDAT >> 9)&0x01)
#define PA10_IN      ((GPIOA->IDAT >> 10)&0x01)
#define PA11_IN      ((GPIOA->IDAT >> 11)&0x01)
#define PA12_IN      ((GPIOA->IDAT >> 12)&0x01)
#define PA13_IN      ((GPIOA->IDAT >> 13)&0x01)
#define PA14_IN      ((GPIOA->IDAT >> 14)&0x01)
#define PA15_IN      ((GPIOA->IDAT >> 15)&0x01)

#define PB0_IN       ((GPIOB->IDAT >> 0)&0x01)
#define PB1_IN       ((GPIOB->IDAT >> 1)&0x01)
#define PB2_IN       ((GPIOB->IDAT >> 2)&0x01)
#define PB3_IN       ((GPIOB->IDAT >> 3)&0x01)
#define PB4_IN       ((GPIOB->IDAT >> 4)&0x01)
#define PB5_IN       ((GPIOB->IDAT >> 5)&0x01)
#define PB6_IN       ((GPIOB->IDAT >> 6)&0x01)
#define PB7_IN       ((GPIOB->IDAT >> 7)&0x01)
#define PB8_IN       ((GPIOB->IDAT >> 8)&0x01)
#define PB9_IN       ((GPIOB->IDAT >> 9)&0x01)
#define PB10_IN      ((GPIOB->IDAT >> 10)&0x01)
#define PB11_IN      ((GPIOB->IDAT >> 11)&0x01)
#define PB12_IN      ((GPIOB->IDAT >> 12)&0x01)
#define PB13_IN      ((GPIOB->IDAT >> 13)&0x01)


#define PIN_0                 ((uint16_t)0x0001)
#define PIN_1                 ((uint16_t)0x0002)
#define PIN_2                 ((uint16_t)0x0004)
#define PIN_3                 ((uint16_t)0x0008)
#define PIN_4                 ((uint16_t)0x0010)
#define PIN_5                 ((uint16_t)0x0020)
#define PIN_6                 ((uint16_t)0x0040)
#define PIN_7                 ((uint16_t)0x0080)
#define PIN_8                 ((uint16_t)0x0100)
#define PIN_9                 ((uint16_t)0x0200)
#define PIN_10                ((uint16_t)0x0400)
#define PIN_11                ((uint16_t)0x0800)
#define PIN_12                ((uint16_t)0x1000)
#define PIN_13                ((uint16_t)0x2000)
#define PIN_14                ((uint16_t)0x4000)
#define PIN_15                ((uint16_t)0x8000)
#define PIN_ALL               ((uint16_t)0xFFFF)


/***** DRIVER API *****/

#define LL_GPIO_PIN_0               ((u16)0x0001)       /*! Pin 0 selected */
#define LL_GPIO_PIN_1               ((u16)0x0002)       /*! Pin 1 selected */
#define LL_GPIO_PIN_2               ((u16)0x0004)       /*! Pin 2 selected */
#define LL_GPIO_PIN_3               ((u16)0x0008)       /*! Pin 3 selected */
#define LL_GPIO_PIN_4               ((u16)0x0010)       /*! Pin 4 selected */
#define LL_GPIO_PIN_5               ((u16)0x0020)       /*! Pin 5 selected */
#define LL_GPIO_PIN_6               ((u16)0x0040)       /*! Pin 6 selected */
#define LL_GPIO_PIN_7               ((u16)0x0080)       /*! Pin 7 selected */
#define LL_GPIO_PIN_8               ((u16)0x0100)       /*! Pin 8 selected */
#define LL_GPIO_PIN_9               ((u16)0x0200)       /*! Pin 9 selected */
#define LL_GPIO_PIN_10              ((u16)0x0400)       /*! Pin 10 selected */
#define LL_GPIO_PIN_11              ((u16)0x0800)       /*! Pin 11 selected */
#define LL_GPIO_PIN_12              ((u16)0x1000)       /*! Pin 12 selected */
#define LL_GPIO_PIN_13              ((u16)0x2000)       /*! Pin 13 selected */
#define LL_GPIO_PIN_14              ((u16)0x4000)       /*! Pin 14 selected */
#define LL_GPIO_PIN_15              ((u16)0x8000)       /*! Pin 15 selected */
#define LL_GPIO_PIN_All             ((u16)0xFFFF)       /*! All Pin selected */


#define LL_GPIO_PIN_SOURCE_0                0x00           /*! Gpio pin source0 pin index 0 */
#define LL_GPIO_PIN_SOURCE_1                0x01           /*! Gpio pin source1 pin index 1 */
#define LL_GPIO_PIN_SOURCE_2                0x02           /*! Gpio pin source2 pin index 2 */
#define LL_GPIO_PIN_SOURCE_3                0x03           /*! Gpio pin source3 pin index 0 */
#define LL_GPIO_PIN_SOURCE_4                0x04           /*! Gpio pin source4 pin index 0 */
#define LL_GPIO_PIN_SOURCE_5                0x05           /*! Gpio pin source5 pin index 0 */
#define LL_GPIO_PIN_SOURCE_6                0x06           /*! Gpio pin source6 pin index 0 */
#define LL_GPIO_PIN_SOURCE_7                0x07           /*! Gpio pin source7 pin index 0 */
#define LL_GPIO_PIN_SOURCE_8                0x08           /*! Gpio pin source8 pin index 0 */
#define LL_GPIO_PIN_SOURCE_9                0x09           /*! Gpio pin source9 pin index 0 */
#define LL_GPIO_PIN_SOURCE_10               0x0A           /*! Gpio pin source10 pin index 0 */
#define LL_GPIO_PIN_SOURCE_11               0x0B           /*! Gpio pin source11 pin index 0 */
#define LL_GPIO_PIN_SOURCE_12               0x0C           /*! Gpio pin source12 pin index 0 */
#define LL_GPIO_PIN_SOURCE_13               0x0D           /*! Gpio pin source13 pin index 0 */
#define LL_GPIO_PIN_SOURCE_14               0x0E           /*! Gpio pin source14 pin index 0 */
#define LL_GPIO_PIN_SOURCE_15               0x0F           /*! Gpio pin source15 pin index 0 */


/***** LL API AND DRIVER API *****/

/**
  * @brief Enumeration constant for GPIO pin alternate function select
  */
typedef enum {
    LL_GPIO_AF_0 = 0,                                       /*! Set GPIO Alternate Function 0 */
    LL_GPIO_AF_1,                                           /*! Set GPIO Alternate Function 1 */
} TYPE_ENUM_LL_GPIO_AF;

/** 
  * @brief  GPIO Bit SET and Bit RESET enumeration 
  */ 
typedef enum{
    LL_GPIO_RESET               = 0,                        /*! BIT_SET means to let the GPIO output a high level */
    LL_GPIO_SET,                                            /*! BIT_RESET means to let the GPIO output a low level */
} TPYE_ENUM_LL_GPIO_BIT_ACTION;

/** 
  * @brief  Enumeration constant for GPIO all mode selec 
  */ 
typedef enum
{
    LL_GPIO_MD_IN_NOPULL        = 0x00,         /*! gpio input no-pull */
    LL_GPIO_MD_IN_UP            = 0x01,         /*! gpio input pull-up */ 
    LL_GPIO_MD_IN_DOWN          = 0x02,         /*! gpio input pull-down */ 
    LL_GPIO_MD_OUT_PP           = 0x03,         /*! gpio output push-pull */  
    LL_GPIO_MD_OUT_OD_NOPULL    = 0x04,         /*! gpio output open-drain no-pull */  
    LL_GPIO_MD_OUT_OD_UP        = 0x05,         /*! gpio output open-drain pull-up */  
    LL_GPIO_MD_AF_NOPULL        = 0x06,         /*! gpio alternate function no-pull */
    LL_GPIO_MD_AF_UP            = 0x07,         /*! gpio alternate function pull-up */    
    LL_GPIO_MD_AF_DOWN          = 0x08,         /*! gpio alternate function pull-down */                    
    LL_GPIO_MD_AF_PP            = 0x09,         /*! gpio alternate function push-pull */
    LL_GPIO_MD_AF_OD_NOPULL     = 0x0A,         /*! gpio alternate function open-drain no-pull */
    LL_GPIO_MD_AF_OD_UP         = 0x0B,         /*! gpio alternate function open-drain pull-up */ 
    LL_GPIO_MD_AN               = 0x0C,         /*! gpio analog */  
} TYPE_ENUM_LL_GPIO_ALL_MODE;

/**
  * @brief Enumeration constant for GPIO pin input output mode select
  */
typedef enum
{ 
    LL_GPIO_MODE_IN             = 0,                /*! GPIO Input Mode */
    LL_GPIO_MODE_OUT            = 1,                /*! GPIO Output Mode */
    LL_GPIO_MODE_AF             = 2,                /*! GPIO Alternate function Mode */
    LL_GPIO_MODE_AN             = 3,                /*! GPIO Analog In/Out Mode */
} TYPE_ENUM_LL_GPIO_MODE;

/**
  * @brief Enumeration constant for GPIO output type select
  */
typedef enum
{
    LL_GPIO_TYPE_OUT_PP         = 0,                /*! Output push-pull (reset state) */  
    LL_GPIO_TYPE_OUT_OD         = 1,                /*! Output open-drain */
} TYPE_ENUM_LL_GPIO_TYPE;

/**
  * @brief Enumeration constant for GPIO speed mode select
  */
typedef enum
{   
    LL_GPIO_SPEED_LEVEL_0       = 0x00,             /*! gpioa/b low speed */
    LL_GPIO_SPEED_LEVEL_1       = 0x01,             /*! gpioa/b speed 1 */ 
    LL_GPIO_SPEED_LEVEL_2       = 0x02,             /*! gpioa/b speed 2 */
    LL_GPIO_SPEED_LEVEL_3       = 0x03,             /*! gpioa/b speed 3 */
    LL_GPIO_SPEED_LEVEL_4       = 0x04,             /*! gpioa/b speed 4 */
    LL_GPIO_SPEED_LEVEL_5       = 0x05,             /*! gpioa/b speed 5 */
    LL_GPIO_SPEED_LEVEL_6       = 0x06,             /*! gpioa/b speed 6 */
    LL_GPIO_SPEED_LEVEL_7       = 0x07,             /*! gpioa/b speed 7 */
} TYPE_ENUM_LL_GPIO_SPEED_LEVEL;

/**
  * @brief Enumeration constant for GPIO pull up pull down select
  */
typedef enum
{
    LL_GPIO_PUPD_NOPULL         = 0,                /*! gpio no pull */ 
    LL_GPIO_PUPD_UP             = 1,                /*! gpio pull up */   
    LL_GPIO_PUPD_DOWN           = 2,                /*! gpio pull down */ 
} TYPE_ENUM_LL_GPIO_PUPD;

/** 
  * @brief  GPIO TG EDGE enumeration 
  */ 
typedef enum{
    LL_GPIO_EDGE_NONE           = 0,             /*! RISING_EDGE means to not detect GPIO edge */
    LL_GPIO_EDGE_RISING         = 1,             /*! FALLING_EDGE means to detect if GPIO has a rising edge */
    LL_GPIO_EDGE_FALLING        = 2,             /*! FALLING_EDGE means to detect if GPIO has a falling edge */
    LL_GPIO_EDGE_RISING_FALLING = 3,             /*! FALLING_EDGE means to detect if GPIO has a rising edge or falling edge */
} TPYE_ENUM_LL_GPIO_TG_EDGE;

/**
  * @brief GPIO Init low layer configuration structure
  */
typedef struct __type_ll_gpio_init {
    u16                                 gpio_pin;           /*! Specifies the GPIO pins to be configured.*/
    TYPE_ENUM_LL_GPIO_MODE              gpio_mode;          /*! Specifies the operating mode for the selected pins.*/
    TYPE_ENUM_LL_GPIO_TYPE              gpio_type;          /*! Specifies the operating mode for the selected pins. */
    TYPE_ENUM_LL_GPIO_SPEED_LEVEL       gpio_speed_level;   /*! Specifies the speed level for the selected pins.*/
    TYPE_ENUM_LL_GPIO_PUPD              gpio_pupd;          /*! Specifies the pull up or down for the selected pins.*/
    TPYE_ENUM_LL_GPIO_TG_EDGE           gpio_edge;          /*! Specifies the edge detection for the selected pins.*/
} TYPE_LL_GPIO_INIT;


/**
  * @}
  */

/** @defgroup GPIO_LL_Interrupt GPIO LL Interrupt Handle function
  * @brief   GPIO LL Interrupt Handle function
  *
@verbatim   
  ===============================================================================
                        Interrupt Handle function
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the GPIO  
    Interrupt Handle function.

    how to use?

    The GPIO interrupt handler uses a callback method that reserves the interface 
    to the user in the form of a callback function. The client needs to initialize 
    the callback function when initializing the GPIO in order for the interrupt to 
    be processed normally. 
   
@endverbatim
  *
  * @{
  */



/**
  * @}
  */
  
/** @defgroup GPIO_LL_Inti_Cfg GPIO LL Initialization And Configuration
  * @brief    GPIO LL Initialization And Configuration
  *
@verbatim   
  ===============================================================================
                        Initialization And Configuration
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the GPIO data 
    Initialization and Configuration.
    
    how to use?

@endverbatim
  *
  * @{
  */

/** 
  * @brief  Initializes the GPIOx peripheral.
  * @param  p_gpio: can be GPIOx where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_initstruct: pointer to a TYPE_LL_GPIO_INIT structure that contains
  *   the configuration information.
  * @retval None.
  */  
void ll_gpio_init(GPIO_TypeDef* p_gpio, TYPE_LL_GPIO_INIT* gpio_initstruct);

/**
  * @brief  Configure the mode for the specified port pin.
  * @param  p_gpio: can be GPIOx where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bit to be Configured.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15).
  * @param  gpio_mode: Specifies the configuration mode
  *   This parameter can be one of the TYPE_ENUM_LL_GPIO_MODE enum values.
  * @retval None.
  */
void ll_gpio_set_mode(GPIO_TypeDef* p_gpio, u16 gpio_pin, TYPE_ENUM_LL_GPIO_MODE gpio_mode);

/**
  * @brief  Configure the output type for the specified port pin.
  * @param  p_gpio: can be GPIOx where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bit to be Configured.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15).
  * @param  gpio_type: Specifies the output type
  *   This parameter can be one of the TYPE_ENUM_LL_GPIO_MODE enum values.
  * @retval None.
  */
void ll_gpio_set_type(GPIO_TypeDef* p_gpio, u16 gpio_pin, TYPE_ENUM_LL_GPIO_TYPE gpio_type);

/**
  * @brief  Configure the pull-up/pull-down state for the specified port pin.
  * @param  p_gpio: can be GPIOx where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bit to be Configured.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15).
  * @param  gpio_pupd: Specifies the pull-up/pull-down state
  *   This parameter can be one of the TYPE_ENUM_LL_GPIO_PUPD enum values.
  * @retval None.
*/
void ll_gpio_set_pupd(GPIO_TypeDef* p_gpio, u16 gpio_pin, TYPE_ENUM_LL_GPIO_PUPD gpio_pupd);

/**
  * @brief  Configure the mode&out type&pupd for the specified port pin.
  * @param  p_gpio: can be GPIOx where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bit to be Configured.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15).
  * @param  gpio_mode: Specifies the configuration mode
  *   This parameter can be one of the TYPE_ENUM_LL_GPIO_MODE enum values.
  * @param  gpio_type: Specifies the output type
  *   This parameter can be one of the TYPE_ENUM_LL_GPIO_MODE enum values.
  * @param  gpio_pupd: Specifies the pull-up/pull-down state
  *   This parameter can be one of the TYPE_ENUM_LL_GPIO_PUPD enum values.
  * @retval None.
*/
void ll_gpio_set_pin(GPIO_TypeDef* p_gpio, u16 gpio_pin, TYPE_ENUM_LL_GPIO_MODE gpio_mode, TYPE_ENUM_LL_GPIO_TYPE gpio_type, TYPE_ENUM_LL_GPIO_PUPD gpio_pupd);

/**
  * @brief  Configure the specified port pin as input mode.
  * @param  p_gpio: can be GPIOx where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bit to be Configured.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15).
  * @param  gpio_pupd: Specifies the pull-up/pull-down state
  *   This parameter can be one of the TYPE_ENUM_LL_GPIO_PUPD enum values.
  * @retval None.
*/
void ll_gpio_set_in_mode(GPIO_TypeDef* p_gpio, u16 gpio_pin, TYPE_ENUM_LL_GPIO_PUPD gpio_pupd);

/**
  * @brief  Configure the specified port pin as output mode.
  * @param  p_gpio: can be GPIOx where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bit to be Configured.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15).
  * @param  gpio_type: Specifies the output type
  *   This parameter can be one of the TYPE_ENUM_LL_GPIO_MODE enum values.
  * @param  gpio_pupd: Specifies the pull-up/pull-down state
  *   This parameter can be one of the TYPE_ENUM_LL_GPIO_PUPD enum values.
  * @retval None.
*/
void ll_gpio_set_out_mode(GPIO_TypeDef* p_gpio, u16 gpio_pin, TYPE_ENUM_LL_GPIO_TYPE gpio_type,TYPE_ENUM_LL_GPIO_PUPD gpio_pupd);

/**
  * @brief  Configure the specified port pin as analog mode.
  * @param  p_gpio: can be GPIOx where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bit to be Configured.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15).
  * @retval None.
*/
void ll_gpio_set_an_mode(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  Configure the specified port pin for work.
  * @param  p_gpio: can be GPIOx where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bit to be Configured.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15).
  * @param  my_mode: Specifies the type
  *   This parameter can be one of the TYPE_ENUM_LL_GPIO_MODE enum values.
  * @retval None.
*/
void ll_gpio_config(GPIO_TypeDef* p_gpio, u16 gpio_pin, TYPE_ENUM_LL_GPIO_ALL_MODE my_mode);

/**
  * @brief  Config gpio speed level.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  * @param  gpio speed level: gpio speed level(LEVEL0-7)
  *   This parameter can be one of the TYPE_ENUM_LL_GPIO_MODE enum values.
  * @retval None.
  */
void ll_gpio_set_speed(GPIO_TypeDef* p_gpio, u16 gpio_pin, TYPE_ENUM_LL_GPIO_SPEED_LEVEL gpio_speed_level);

/**
  * @brief  Config gpio pin alternate function mode.
  * @param  p_gpio: where x can be (A..C) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  * @param  gpio type(push-pull/open-drain)
  * @param  gpio_pupd: gpio pull type(pull-up/pull-down)
  * @retval None.
  */
void ll_gpio_set_af_mode(GPIO_TypeDef* p_gpio, u16 gpio_pin, TYPE_ENUM_LL_GPIO_TYPE gpio_type,TYPE_ENUM_LL_GPIO_PUPD gpio_pupd);

/**
  * @brief  Config gpio pin alternate function mode.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  * @param  gpio_af:(LL_GPIO_AF_0/LL_GPIO_AF_1)
  * @retval None.
  */
void ll_gpio_af_sel(GPIO_TypeDef* p_gpio, u16 gpio_pin, TYPE_ENUM_LL_GPIO_AF gpio_af);

/**
  * @brief  Sets the selected data port bits.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15).
  * @retval None.
  */
void ll_gpio_set_bits(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  Clears the selected data port bits.
  * @param  p_gpio: where x can be (A..C) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15).
  * @retval None.
  */
void ll_gpio_reset_bits(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  Config gpio port toggle.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15). 
  * @retval None.
  */
void ll_gpio_toggle(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  Write the specified GPIO output data port.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_set_value: gpio set value.
  * @retval None.
  */
void ll_gpio_write_data(GPIO_TypeDef* p_gpio, u32 gpio_set_value);

/**
  * @brief  Reads the specified GPIO output data port.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @retval GPIO output data port value.
  */
u16 ll_gpio_read_output_data(GPIO_TypeDef* p_gpio);

/**
  * @brief  Read the specified output data port bit.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: Specifies the port bit to read.
  * @note   This parameter can be LL_GPIO_PIN_x where x can be:(0..15) for GPIOA, 
  *   (0..9) for GPIOB.
  * @retval The output port pin value.
  */
u8 ll_gpio_read_output_data_bit(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  Reads the specified input port pin.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @retval The input port pin value.
  */
u16 ll_gpio_read_input_data(GPIO_TypeDef* p_gpio);

/**
  * @brief  Reads the specified input port pin.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bit to read.
  * @note   This parameter can be LL_GPIO_PIN_x where x can be:(0..15) for GPIOA, 
  *   (0..9) for GPIOB.
  * @retval The input port pin value.
  */
u8 ll_gpio_read_input_data_bit(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  Writes data to the specified GPIO data port.
  * @param  p_gpio: where x can be (A or B) to select the GPIO peripheral.
  * @param  gpio_pin_src: specifies the pin for the Alternate function.
  *   This parameter can be GPIO_PinSourcex where x can be (0..15).
  * @param  gpio_af: selects the pin to used as Alternate function.
  *   This parameter can be one of the following value:
  *            @arg LL_GPIO_AF_0   
  *            @arg LL_GPIO_AF_1   

  * @note   The pin should already been configured in Alternate Function mode(AF)
  *   using GPIO_InitStruct->GPIO_MODE = GPIO_MODE_AF.
  * @note   Refer to the Alternate function mapping table in the device datasheet 
  *   for the detailed mapping of the system and peripherals'alternate 
  *   function I/O pins.
  * @retval None.
  */
void ll_gpio_pin_af_config(GPIO_TypeDef* p_gpio, u16 gpio_pin_src, TYPE_ENUM_LL_GPIO_AF gpio_af);

/**
  * @brief  Config gpio irq.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15).
  * @param  edge£RRISING or FALLING
  * @param  newstate: DISABLE or ENABLE.
  * @retval None.
  */
void ll_gpio_irq_config(GPIO_TypeDef* p_gpio, u16 gpio_pin, TPYE_ENUM_LL_GPIO_TG_EDGE edge);

/**
  * @brief  gpio irq enable.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15).
  * @param  newstate: DISABLE or ENABLE.
  * @retval None.
  */
void ll_gpio_irq_enable(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  gpio irq enable.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15).
  * @retval None.
  */
void ll_gpio_irq_disable(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  Clear gpio port pending.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15). 
  * @retval None.
  */
void ll_gpio_port_pend_clear(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  Get gpio port pending.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15). 
  * @retval The selected port pending value.
  */
u32 ll_gpio_port_pend_get(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  enable gpio ie en.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15). 
  * @retval None.
  */
void ll_gpio_port_ieen_enable(GPIO_TypeDef* p_gpio, u16 gpio_pin);

/**
  * @brief  disable gpio ie en.
  * @param  p_gpio: where x can be (A..B) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *   This parameter can be any combination of LL_GPIO_PIN_x where x can be (0..15). 
  * @retval None.
  */
void ll_gpio_port_ieen_disable(GPIO_TypeDef* p_gpio, u16 gpio_pin);
/**
  * @}
  */

/** @defgroup GPIO_LL_Data_Transfers GPIO LL Data transfers functions
  * @brief    GPIO LL Data transfers functions 
  *
@verbatim   
  ===============================================================================
                            Data transfers functions
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the GPIO data 
    transfers and receive.
  
@endverbatim
  *
  * @{
  */
  
/**
  * @brief  Low layer timer get gpio irq pending
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_GPIO_PENDING_GET(p_gpio, gpio_pin)               ((p_gpio)->TGPEND & gpio_pin)

/**
  * @brief  Low layer timer clear gpio irq pending
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_GPIO_PENDING_CLR(p_gpio, gpio_pin)               ((p_gpio)->TGPEND = gpio_pin)

/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

/**
  * @}
  */

/**
  * @}
  */

#endif //__JS32T031_LL_GPIO_H

/*************************** (C) COPYRIGHT 2022 JUSHENG ***** END OF FILE *****/
